package com.ljq.cksp.controller;

import com.ljq.cksp.pojo.Document;
import com.ljq.cksp.pojo.Result;
import com.ljq.cksp.service.DocumentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author:ljq
 * @Date:2020/3/3
 */
@RestController
@RequestMapping("/document")
public class DocumentController {
    @Autowired
    DocumentService documentService;

    @GetMapping
    public Result query(@RequestParam("mode")String mode, @RequestParam("keyword")String keyword,
                        @RequestParam(value="start", defaultValue="0") int start, @RequestParam(value="size", defaultValue="10") int size){
        Result result = new Result();
        Page<Document> data = null;
        if("fact".equals(mode)){
            data = documentService.queryByFact(keyword, start, size);
        }else {
            data = documentService.queryByAccusation(keyword, start, size);
        }
        result.setData(data);
        return result;
    }
}
